<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        //promise.race后台请求超时，(那个返回的快就返回谁)
         let promise1=new Promise((resolve,reject)=>{
           setTimeout(() => {
            reject("第一个的=>拒绝"); 
           }, 1000);
        });
        let promise2=new Promise((resolve,reject)=>{
            setTimeout(() => {
            resolve("第二个的=>解决");
           }, 2000);
        });

      Promise.race([promise1,promise2]).then(value=>{
          console.log(value);//第一个的=>拒绝
      }).catch(error=>console.log(error))









      //可以设置settimeout来设置一个时间如果大于这个时间就为超时

      function get_http(){
         
        return new  Promise((resolve,reject)=>{
            setTimeout(() => {
                   reject("请求超时");
                }, 3000);
        })
         }
      

      let promise_get=new Promise((resolve,reject)=>{
         setTimeout(() => {
            resolve("请求成功");
         }, 6000);
      })
      Promise.race([get_http(),promise_get]).then(value=>{
          console.log(value);//请求超时
      }).catch(error=>console.log(error))
    </script>
</body>
</html>